{extend name="common/layout" /}
{block name="main"}
<div class="admin-main layui-anim layui-anim-upbit">
    <div class="padding30">
        <h3 class="page-box-title">{:lang('Subscribe Report')}</h3>
        <div class="demoTable">
        
        <div style="clear: both;"></div>
    </div>
    </div>
    
     <div class="" id="_listBox">
        <div style="text-align: right;"><a href="{:url('setup')}" class="layui-btn layui-btn-normal layui-btn-add borderrad5 _showmodel " title="{:lang('Add')}" ><i class="icon icon-plus"></i></a></div>

        <table class="layui-table" id="list" lay-filter="list"></table>
    </div>
</div>
{/block}
{block name="footer"}
<script type="text/html" id="status">
    <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="{:lang('No|Off')}" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">

    <a href="{:url('setup')}?id={{d.id}}" class="">{:lang('Edit')}</a> |
    <a class="" lay-event="delete">{:lang('Delete')}</a>
</script>
   <script type="text/javascript">
   	layui.use(['table','layer'], function() {
   		 var table = layui.table, $ = layui.jquery, layer = layui.layer,form = layui.form;;
   		 var tableIn = table.render({
            id: 'message',
            elem: '#list'
            ,url: '{:url("",array('is_red'=>$is_red))}',
            method:'post',
            page:getPageThume()
            ,cols: [[
                // {checkbox: true, fixed: true},
                {field:'type', title: "{:lang('Subscribe Data')}", width:"15%"}
                ,{field:'email', title: "{:lang('Send Email')}", width:"20%"}
                ,{field:'month', title: "{:lang('Time Cycle')}", width:"10%"}
                ,{field:'status', title: "{:lang('If?')}", width:"10%",toolbar: '#status'}
                // ,{field:'create_time', title: "{:lang('Create Time')}", width:"15%",sort:true}
                ,{width:'15%',title: "", align:'right', toolbar: '#action'}
            ]]
        });
        //搜索
        $('#search').on('click', function () {
            var key = $('#key').val();
            tableIn.reload({
                where: {key: key}
            });
        });
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'delete'){
                layer.confirm('{:lang("确定删除吗?")}', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('delete')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
        form.on('switch(status)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var status = obj.elem.checked===true?1:0;
            $.post('{:url("editState")}',{'id':id,'status':status},function (res) {
                layer.close(loading);
                if (res.code==1) {
                    layer.msg(res.msg,{time:1000,icon:1});
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
    })
   </script>
{/block}